<template>
    <ShopPageHead></ShopPageHead>
    <main class="index_main" id="all_vue">
        <HomeAdvertising :imgurl="adImg1"></HomeAdvertising>
        <ShopSubMenu></ShopSubMenu>
        <!-- 当前位置 -->
        <div class="categ_crumb_box2 clearfix_2">
            <div class="categ_crumb_left">
                <span class="categ_crumb_left_a" title=""> 当前位置： </span>
                <NuxtLink
                    :to="`/xiangcunshangcheng/index.html`"
                    class="categ_crumb_left_a"
                >
                    乡村商城
                </NuxtLink>
                &gt;
                <NuxtLink
                    :to="`/xiangcunshangcheng/${targetSegment}/index.html`"
                    class="categ_crumb_left_a"
                >
                    {{name}}
                </NuxtLink>
                &gt;
                <NuxtLink
                    :to="`/xiangcunshangcheng/${targetSegment}/qiugou/list-1.html`"
                    class="categ_crumb_left_a"
                >
                    求购
                </NuxtLink>
                &gt;
                <span class="categ_crumb_left_text">{{shopData.name}}</span>
            </div>
        </div>

        <div class="supply_1_index_qiugou clearfix">
            <div class="supply_1_index_qiugou_left">
                <img class="supply_1_img" :src="shopImg" :alt="shopData.name">
                <div class="supply_1_right_qiugou">
                    <h4 class="supply_1_h4">{{shopData.name}}</h4>
                    <div class="supply_1_ul_qiugou clearfix">
                        <div class="supply_1_li_qiugou clearfix"><label class="supply_1_li_label">发布日期</label><span
                            class="supply_1_li_text ">{{getTimeText(shopData.created_at)}}</span></div>
                        <div class="supply_1_li_qiugou clearfix"><label class="supply_1_li_label">截止日期</label><span
                            class="supply_1_li_text ">{{getValidityTime(shopData)}}</span></div>
                        <div class="supply_1_li_qiugou clearfix"><label class="supply_1_li_label">浏览次数</label><span
                            class="supply_1_li_text ">{{ shopData.hits }}</span></div>
                        <div class="supply_1_li_qiugou clearfix"><label class="supply_1_li_label">联 系 人</label><span
                            class="supply_1_li_text ">{{ shopData.contact}}</span></div>
                        <div class="supply_1_li_qiugou clearfix"><label class="supply_1_li_label">发布地区</label><span
                            class="supply_1_li_text ">{{ shopData.address }}</span></div>
                        <div class="supply_1_li_qiugou clearfix"><label class="supply_1_li_label">座 机</label><span
                            class="supply_1_li_text ">{{ shopData.landline }}</span></div>
                        <div class="supply_1_li_qiugou clearfix"><label class="supply_1_li_label">联系电话</label><span
                            class="supply_1_li_text ">{{ shopData.phone }}</span></div>
                    </div>
                </div>
            </div>

            <div class="supply_1_index_qiugou_right">
                <div class="shop_3_right clearfix">
                    <div class="choice_1_box clearfix">
                        <div class="choice_1_btn_box clearfix">
                            <div class="choice_1_btn" 
                                :class="{ choice_1_btn_only: choice_1_num == 1 }"
                                @mouseover="choice_1_num = 1">
                                <span class="choice_1_btn_a">供应商品</span>
                            </div>
                            <div class="choice_1_btn" 
                                :class="{ choice_1_btn_only: choice_1_num == 2 }"
                                @mouseover="choice_1_num = 2">
                                <span class="choice_1_btn_a">求购商品</span>
                            </div>
                        </div>
                        <div class="choice_1_card_box">
                            <div class="shop_ul_img_2 choice_1_card clearfix" v-show="choice_1_num == 1">
                                <div class="shop_li_img_2" v-for="(item,index) in boxData1">
                                    <nuxtLink 
                                        :to="getShopPathDetail1(item)"
                                        class="shop_li_img_2_a"
                                    >
                                        <div class="shop_li_img_2_num"> {{ index + 1 }} </div>
                                        <div class="shop_li_img_2_right clearfix">
                                            <img class="shop_li_img_2_img" :src="item.imgurl" :alt="item.name">
                                            <div class="shop_li_img_2_text">
                                                {{item.name}}
                                            </div>
                                        </div>
                                    </nuxtLink>
                                </div>
                            </div>
                            <div class="shop_ul_img_2 choice_1_card clearfix" v-show="choice_1_num == 2">
                                <div class="shop_li_img_2" v-for="(item,index) in boxData2">
                                    <nuxtLink 
                                        :to="getShopPathDetail1(item)"
                                        class="shop_li_img_2_a"
                                    >
                                        <div class="shop_li_img_2_num"> {{ index + 1 }} </div>
                                        <div class="shop_li_img_2_right clearfix">
                                            <img class="shop_li_img_2_img" :src="item.imgurl" :alt="item.name">
                                            <div class="shop_li_img_2_text">
                                                {{item.name}}
                                            </div>
                                        </div>
                                    </nuxtLink>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>
        <div class="supply_2_index clearfix">

            <div class="supply_head_box clearfix_2">
                <a class="supply_head_a" title="" :class="{ supply_head_a_only: 1 == supply_choice_1_num }"
                    @mouseover="supply_choice_1_num = 1">详情信息</a>
                <a class="supply_head_a" title="" :class="{ supply_head_a_only: 2 == supply_choice_1_num }"
                    @mouseover="supply_choice_1_num = 2">发布人信息</a>
            </div>

            <div class="supply_art_out clearfix">
                <!-- 详情信息 -->
                <div class="supply_art_box" v-show="supply_choice_1_num == 1" v-html="shopData.detail"></div>
                <!-- 发布人信息 -->
                <div class="supply_art_box" v-show="supply_choice_1_num == 2">
                    <p class="supply_art_box_p">公司名称：</p>
                    <p class="supply_art_box_p">电子邮箱：{{shopData.email}}</p>
                    <p class="supply_art_box_p">邮政编码：{{shopData.postal}}</p>
                    <p class="supply_art_box_p">联系地址：{{shopData.address}}</p>
                </div>
            </div>
        </div>
        <ShopHotNews></ShopHotNews>
    </main>
    <HomeFoot></HomeFoot>
</template>

<script setup>
//1.页面必备方法 start ---------------------------------------->
import { ref, onMounted } from 'vue'
import { ElRadio, ElRadioGroup } from 'element-plus'
//1.2选项卡 
const supply_choice_1_num = ref(1)
//1.3是否展示有效期
const getValidityTime = (shopData) => {
    if(shopData.islong==1){
        return "无期限"
    }else{
        if(shopData.validity){
            return shopData.validity.split(' ')[0];
        }
    }
}
//1.4 格式化字符串时间
const getTimeText = (time) => {
    if(time){
        return time.split(' ')[0];
    }else{
        return '';
    }
}
// 1.4应商品与求购商品的选项卡	
const choice_1_num = ref(1)
//1.页面必备方法 end ---------------------------------------->

//2.页面路径 start ---------------------------------------->
//2.1 获得页面数据id
const route = useRoute();
const router = useRouter()
let articleId = 0; //把路径转换为数据id
const name = ref('') //当前频道名称
const targetSegment = getRoutePath(2);//返回第二层的路径id
//通过导航路径反向查询导航id
const getRouteId = await requestDataPromise('/web/getWebsiteRoute', {
    method: 'GET',
    query: {
        'pinyin': targetSegment,
    },
});
if(getRouteId.code == 200){
    articleId = getRouteId.data.category_id;
    name.value = getRouteId.data.alias;
}else{
    console.log("错误位置：获得页面路径")
}


//2.3 获得子栏目列表
const secondNav = ref([]);
const selectedSecondId = ref(route.query.catid);//当前选中了哪个子导航
let getSecondNav = async () => {
    const listData = await requestDataPromise('/web/getWebsiteModelCategory', {
        method: 'GET',
        query: {
            'placeid': 1,
            'pid': articleId,
            'num': 50,
        },
    });
    if (listData.code == 200) {
        secondNav.value = listData.data
    } else {
        console.log("错误位置：获得子级栏目列表")
    }
}
getSecondNav();

//2.4 获得cityid
const cityId = ref(route.query.cityid)
//2.页面路径 end ---------------------------------------->

//3.获得商品详情 start ---------------------------------------->
const shopId = ref(route.params.id) //获得商品的id
const shopData = ref({});
const shopImg = ref("")

let getShopData = async () => {
    const shopReq = await requestDataPromise('/web/getWebsiteshopInfo', {
        method: 'GET',
        query: {
            'id': parseFloat(shopId.value),
        },
    });

    if (shopReq.code == 200) {
        console.log(667788)
        console.log(shopReq)
        shopData.value = shopReq.data
        shopImg.value = shopReq.data.imgurl[0]
    } else {
        console.log("错误位置：获得商品详情")
    }
}
getShopData();

//获得右侧供应与求购的内容
const boxData1 = ref([]) //供应商品
const boxData2 = ref([]) //求购商品

//创建请求数据json
let getJson = [
    {"level":"5,0,6"},//供应商品
    {"level":"6,0,6"},//求购商品
]

let jsonString = JSON.stringify(getJson)

//获取所有数据
async function getPageAllData() {
    const mkdata = await requestDataPromise('/web/getWebsiteshop', {
        method: 'GET',
        query: {
            'catid': 346,
            'id': jsonString,
        },
    });

    if (mkdata.code == 200) {
        //供应商品
        boxData1.value = mkdata.data.goods[0];
        //求购商品
        boxData2.value = mkdata.data.goods[1];
    } else {
        ElMessage.error(mkdata.message)
    }
}
getPageAllData();
//3.获得商品详情 end  ---------------------------------------->

//5.广告 start ---------------------------------------->
//获得所有广告
let adImg1 = ref({})
onMounted(async () => {
    const { $webUrl, $CwebUrl } = useNuxtApp();
    //从客户端启动广告
    //广告1
    let url = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=xcw_shopdetail_0001`
    const responseAd1 = await fetch(url, {
        headers: {
            'Content-Type': 'application/json',
            'Userurl': $CwebUrl,
            'Origin': $CwebUrl
        }
    });
    const resultAd1 = await responseAd1.json();
    adImg1.value = resultAd1.data[0];
})
//5.广告 end ---------------------------------------->
</script>
<style lang="less" scoped>
@import '@/assets/css/shop/detail.less';
</style>